package avicit.bdp.dgs.qa.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2023-05-30
 * @类说明：BackgroundTaskService
 * @修改记录：
 * @注意事项：
 * @主要功能：数据质量后台任务
 *          1、工单处理任务；（从redis消息队列中获取待生成工单，自动生成工单）
 *          2、其他
 */
@Component
public class BackgroundTaskService {
    private static final Logger logger = LoggerFactory.getLogger(BackgroundTaskService.class);

    @Autowired
    private WorkOrderService workOrderService;

    @Autowired
    private JobReportService jobReportService;

    @PostConstruct
    public void initialize() {
        logger.info("初始化数据质量后台线程...");

        initWorkOrderThread();
        initJobReportThread();
    }

    /**
     * 初始化生成工单线程
     */
    private void initWorkOrderThread() {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                workOrderService.run();
            }
        });
        thread.setName("dataQualityWorkOrderBGThread");
        thread.start();
    }

    /**
     * 初始化生成质量报告线程
     */
    private void initJobReportThread() {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                jobReportService.run();
            }
        });
        thread.setName("dataQualityJobReportBGThread");
        thread.start();
    }
}
